home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / ISp Sample / Source / MenuHandler.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.0 KB  |  152 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MenuHandler.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (BWS)    Brent Schorsch
  21.  
  22.     Change History (most recent first):
  23.  
  24.        <SP1>      7/1/99    BWS        first checked in
  25. */
  26.  
  27. //•    ————————————————————————————————————————    Includes
  28.  
  29. #include <Devices.h>
  30. #include <Processes.h>
  31. #include <ToolUtils.h>
  32. #include <Windows.h>
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. #include "AboutBox.h"
  38. #include "AppShellResources.h"
  39. #include "EventHandler.h"
  40. #include "MemoryHandler.h"
  41. #include "MenuHandler.h"
  42. #include "ShellWindow.h"
  43.  
  44. //•    ————————————————————————————————————————    Private Definitions
  45. //•    ————————————————————————————————————————    Private Constants
  46. //•    ————————————————————————————————————————    Private Types
  47. //•    ————————————————————————————————————————    Private Structs
  48. //•    ————————————————————————————————————————    Private Variables
  49.  
  50. static Boolean gMenuHandlerInited = false;
  51.  
  52. //•    ————————————————————————————————————————    Private Functions
  53. //•    ————————————————————————————————————————    Public Variables
  54.  
  55. //•    ————————————————————    MenuInit
  56.  
  57. void
  58. MenuInit(void)
  59. {
  60. Handle        theMenuBar;
  61.     
  62.     //•    Load the menu bar
  63.     theMenuBar = GetNewMBar(kMBAR_Main);
  64.     if (theMenuBar == nil)
  65.         ExitToShell();
  66.  
  67.     //•    Install the menu bar
  68.     SetMenuBar(theMenuBar);
  69.  
  70.     //•    Add Apple Menu items
  71.     AppendResMenu(GetMenuHandle(kMENU_Apple), 'DRVR');
  72.     DisposeHandleZ(&theMenuBar);
  73.  
  74.     DrawMenuBar();
  75.  
  76.     gMenuHandlerInited = true;
  77. }
  78.  
  79. //•    ————————————————————    MenuPrepForSelect
  80.  
  81. void
  82. MenuPrepForSelect(void)
  83. {
  84.     DrawMenuBar();
  85. }
  86.  
  87. //•    ————————————————————    MenuDoChoice
  88.  
  89. Boolean
  90. MenuDispatch(SInt32 inMenu, const short inModifiers)
  91. {
  92. SInt16        theMenu;
  93. SInt16        theItem;
  94. UInt32        menuCommand;
  95. MenuHandle    theMenuHandle;
  96. Boolean        handled = true;
  97. WindowPtr    whichWindow;
  98. ShellWindow    *myWindow = nil;
  99.  
  100.     if (false == gMenuHandlerInited)
  101.         return (false);
  102.         
  103.     theMenu = HiWord(inMenu);
  104.     theItem = LoWord(inMenu);
  105.     theMenuHandle = GetMenuHandle(theMenu);
  106.  
  107.     //•    Small hackish thing because the menu command stuff doesn't
  108.     //•    bother mentioning that you got a desk accessory.
  109.     if ((kMENU_Apple == theMenu) && (theItem > 2))
  110.     {
  111.     Str255    daName;
  112.     GrafPtr    oldPort;
  113.     
  114.         GetPort(&oldPort);
  115.         GetMenuItemText(theMenuHandle, theItem, daName);
  116.         OpenDeskAcc(daName);
  117.         SetPort(oldPort);
  118.     }
  119.     else
  120.     {
  121.         GetMenuItemCommandID(theMenuHandle, theItem, &menuCommand);
  122.     
  123.         whichWindow = FrontWindow();
  124.         if (userKind == GetWindowKind(whichWindow))
  125.             myWindow = (ShellWindow *) GetWRefCon(whichWindow);
  126.     
  127.         if (nil != myWindow)
  128.             handled = (myWindow->Menu(menuCommand, inModifiers));
  129.         
  130.         if (!handled)
  131.             switch (menuCommand)
  132.             {
  133.                 case kMenuCMD_AboutBox:
  134.                     AboutBox();
  135.                     break;
  136.                     
  137.                 case kMenuCMD_Quit:
  138.                     gDone = true;
  139.                     break;
  140.     
  141.                 default:
  142.                     handled = false;
  143.                     break;
  144.             }
  145.     }
  146.  
  147.     HiliteMenu(0);
  148.     DrawMenuBar();
  149.  
  150.     return (handled);
  151. }
  152.